package com.example.pinkcat.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.VideoActivity;
import com.example.pinkcat.activity.VideoPinkcat;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.example.pinkcat.api.entity.VideowaibuEntity;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

public class Fenqu_qm_adapter extends RecyclerView.Adapter<Fenqu_qm_adapter.ViewHolder> {

    public Context context;

    int fenqu_port;

    String agreementData;



    List<VideowaibuEntity> videoMsgArrayList=new ArrayList<>();

    public void addData(List<VideowaibuEntity> videoEntities){
        this.videoMsgArrayList.addAll(videoEntities);
        notifyDataSetChanged();
    }


    public Fenqu_qm_adapter(Context context , Integer fenqu_port){
            this.context = context;
            this.fenqu_port = fenqu_port;
    }



    static class ViewHolder extends RecyclerView.ViewHolder{

        private RecyclerView fenqu_rv;
        private TextView fenqu_tx;

        public RoundedImageView imageView_nomorl;
        public TextView textViewDescription_nomorl;
        public TextView textViewTitlte_nomorl;


        public TextView list_video_tx_pf;
        public TextView list_video_tx_pl;

        public View v;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);


            imageView_nomorl=itemView.findViewById(R.id.lis_manga_img_nomorl);
            textViewTitlte_nomorl=itemView.findViewById(R.id.manga_title_nomorl);
            textViewDescription_nomorl=itemView.findViewById(R.id.manga_descrptioon_nomorl);

            list_video_tx_pf = itemView.findViewById(R.id.list_video_tx_pf);
            list_video_tx_pl = itemView.findViewById(R.id.list_video_tx_pl);

            v= itemView.findViewById(R.id.video_normal);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(context).inflate(R.layout.layout_manga_fenqu,parent,false);

        return new Fenqu_qm_adapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {


        holder.textViewTitlte_nomorl.setText(videoMsgArrayList.get(position).getVideo_name()); //视频标题
        holder.textViewDescription_nomorl.setText(videoMsgArrayList.get(position).getVideo_info()); //视频描述
        Glide.with(context).load(Uri.parse(videoMsgArrayList.get(position).getVideo_cover())).into(holder.imageView_nomorl); // 视频封面
        holder.list_video_tx_pf.setText(String.valueOf(videoMsgArrayList.get(position).getTotalplay())); //播放量
        holder.list_video_tx_pl.setText(String.valueOf(videoMsgArrayList.get(position).getComment_count())); //评论量

        holder.v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (videoMsgArrayList.get(position).getVideo_type().equals("动漫")
                        ||videoMsgArrayList.get(position).getVideo_type().equals("电视剧")
                        ||videoMsgArrayList.get(position).getVideo_type().equals("电影")
                        ||videoMsgArrayList.get(position).getVideo_type().equals("综艺")){
                    Intent intent = new Intent(context, VideoPinkcat.class);
                    intent.putExtra("v_id",videoMsgArrayList.get(position).getVideo_id());
                    intent.putExtra("up_id",videoMsgArrayList.get(position).getUser_id());
                    intent.putExtra("v_link",videoMsgArrayList.get(position).getVideo_link());
                    intent.putExtra("v_labs",videoMsgArrayList.get(position).getVideo_lab());
                    context.startActivity(intent);
                }else {
                Intent intent = new Intent(context, VideoActivity.class);
                intent.putExtra("v_id",videoMsgArrayList.get(position).getVideo_id());
                intent.putExtra("up_id",videoMsgArrayList.get(position).getUser_id());
                intent.putExtra("v_link",videoMsgArrayList.get(position).getVideo_link());
                intent.putExtra("v_labs",videoMsgArrayList.get(position).getVideo_lab());
                context.startActivity(intent); }
            }
        });
    }


    @Override
    public int getItemCount()
    {
        return videoMsgArrayList.size();
    }
}
